package com.eqdd.yiqidian.ui.companyspace

import android.view.View
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.adapter.BGABannerAdapter
import com.eqdd.yiqidian.base.BaseActivity
import com.eqdd.yiqidian.bean.CompanyDetailBean
import com.eqdd.yiqidian.http.HttpConfig
import com.eqdd.yiqidian.http.HttpResult
import com.eqdd.yiqidian.http.JsonCallBack
import com.eqdd.yiqidian.kotlin.imgPathPreview
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_company_introduce.*
import org.jetbrains.anko.toast

/**
 * Created by jhj on 18-7-6.
 */
class CompanyIntroduceActivity : BaseActivity() {

    private var companyDetailBean: CompanyDetailBean? = null

    override fun initBinding() {
        setContentView(R.layout.activity_company_introduce)
        initTopTitleBar(View.VISIBLE, "公司简介")

    }

    override fun initData() {
        OkGo.post<HttpResult<CompanyDetailBean>>(HttpConfig.BASE_URL + HttpConfig.COMPANY_SPACE_DETAIL)
                .params("userGuid", user.guid)
                .params("userGompanyId", user.companyId)
                .params("companyId", user.companyId)
                .execute(object : JsonCallBack<HttpResult<CompanyDetailBean>>() {
                    override fun onSuccess(response: Response<HttpResult<CompanyDetailBean>>?) {
                        val result = response?.body()
                        if (result?.status == 200) {
                            companyDetailBean = result.items
                            setView()

                        } else {
                            toast(result?.msg ?: "获取信息失败")
                            finish()
                            return
                        }
                    }

                })
    }

    override fun setView() {
        companyDetailBean?.let {
            banner_viewpager.setAdapter(BGABannerAdapter(this))
            banner_viewpager.setData(it.comImage.map { it.imgUrl }, null)
            richEditor.setInputEnabled(false)
            richEditor.setPadding(10, 0, 10, 0)
            val html = it.comDesc
                    ?.replace("<pre>", "")
                    ?.replace("</pre>", "")
                    ?.replace("<br>", "")
            richEditor.html = html
            banner_viewpager.setDelegate { banner, itemView, model, position ->
                imgPathPreview(it.comImage.map { it.imgUrl }, position)
            }
        }
    }
}